<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仪器信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
<!--        <div class="col-sm-12 search-collapse">-->
<!--            <form id="formId">-->
<!--                <div class="select-list">-->
<!--                    <ul>-->
<!--                        <li>-->
<!--                            <input type="text" name="deviceName" placeholder="请输入仪器名称"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <input type="text" name="createPerson" placeholder="请输入创建人">-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <input type="text" name="type" placeholder="请输入型号规格"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <select class="input-sm form-control" id="useStatus">-->
<!--                                <option value="请选择状态">请选择状态</option>-->
<!--                                <option value="0">未出库</option>-->
<!--                                <option value="1">已出库</option>-->
<!--                            </select>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>-->
<!--                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>-->
<!--                        </li>-->
<!--                    </ul>-->
<!--                </div>-->
<!--            </form>-->
<!--        </div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('device:information:remove')}]];
    var detailFlag = [[${@permission.hasPermi('device:information:detail')}]];
    var useStatus = [[${@dict.getType('tmd_device_record_gooutflag')}]];
    var prefix = ctx + "device/myUse";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "使用记录",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'gooutFlag',
                    title: '标记',
                    visible: false
                },
                {
                    title: "编号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    },
                    align: 'center',
                },
                {
                    field: 'deviceName',
                    title: '仪器名称',
                    align: 'center',
                },
                {
                    field: 'type',
                    title: '型号规格',
                    align: 'center',
                },
                {
                    field:'savePosition',
                    title:'存放位置',
                    align: 'center',
                },
                {
                    field: 'createPerson',
                    title: '创建人',
                    align: 'center',
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                },
                {
                    field: 'gooutFlag',
                    title: '操作名称',
                    align: 'center',
                    formatter: function (value) {
                        return $.table.selectDictLabel(useStatus, value);
                    },
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (row.gooutFlag === 0 && row.useStatus === '1'){
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs"  href="javascript:void(0)" onclick = "ifs(\'' + row.id + '\')"  id="ifs '+ row.id + '"  ><i class="fa fa-edit"></i>入库</a> ');
                        }else{
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs"  disabled="true"  href="javascript:void(0)"   id="ifs '+ row.id + '"  ><i class="fa fa-edit"></i>入库</a> ');

                        }
                        console.log(row.gooutFlag === 0)
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>

<script>
    function ifs(id){
        $.ajax({
            type: "POST",
            url: prefix + "/ifs",
            data: {id: id},
            success: function (response) {
                alert('入库成功');
                location.reload();
            },
            error:function (xhr,status,error){
                alert('入库失败' + xhr.responseText);
            },
        })
    }
</script>
</body>
</html>